<!--
 * 加载更多
 * @作者: 陈老师儿~
 * @手机: 18560000860
 -->
<template>
    <view class="pure-loadmore" :class="classes" :style="styles" @tap="handleClick">
        <!-- 加载更多 -->
        <view class="pure-loadmore-status pure-loadmore-more" v-if="status === 'more'">
            <!-- 兼容京东多slot写法 -->
            <slot name="more" v-if="$slots.more"></slot>
            <text class="pure-loadmore-status-text pure-loadmore-more-text" v-else>{{ more }}</text>
        </view>

        <!-- 加载中 -->
        <view class="pure-loadmore-status pure-loadmore-loading" v-else-if="status === 'loading'">
            <!-- 兼容京东多slot写法 -->
            <slot name="loading" v-if="$slots.loading"></slot>

            <view class="pure-loadmore-loading-icon" v-if="!$slots.loading">
                <pure-icon :name="icon"></pure-icon>
            </view>
            <text class="pure-loadmore-status-text pure-loadmore-loading-text" v-if="!$slots.loading">{{ loading }}</text>
        </view>

        <!-- 加载失败 -->
        <view class="pure-loadmore-status pure-loadmore-fail" v-else-if="status === 'fail'">
            <!-- 兼容京东多slot写法 -->
            <slot name="fail" v-if="$slots.fail"></slot>
            <text class="pure-loadmore-status-text pure-loadmore-fail-text" v-else>{{ fail }}</text>
        </view>

        <!-- 没有更多 -->
        <view class="pure-loadmore-status pure-loadmore-nomore" v-else-if="status === 'nomore'">
            <!-- 兼容京东多slot写法 -->
            <slot name="nomore" v-if="$slots.nomore"></slot>
            <text class="pure-loadmore-status-text pure-loadmore-nomore-text" v-else>{{ nomore }}</text>
        </view>
    </view>
</template>

<script>
    import props from "./props.js";
    export default {
        options: {
            // 将自定义节点设置成虚拟的
            // 头条、飞书：因为合并后丢失事件和 'provide/inject'
            // 京东：因为合并后不能合并外层 'class'
            // 百度：因为合并后会在控制台疯狂报警告
            // #ifndef MP-TOUTIAO || MP-LARK || MP-JD || MP-BAIDU
            virtualHost: true,
            // #endif

            // 组件样式隔离
            styleIsolation: "apply-shared",

            // 允许使用多个插槽
            multipleSlots: true,
        },
        props,
        emits: ["onClick"],
        computed: {
            // classes
            classes() {
                const classes = [];

                // 禁用
                if (this.disabled) classes.push(this.disabledClass);

                return classes;
            },

            // styles
            styles() {
                const styles = [];
                return styles;
            },
        },
        methods: {
            handleClick() {
                // 禁用了
                if (this.disabled) return;

                this.$emit("onClick");
            },
        },
    };
</script>

<style scoped>
    @import "./style.css";
</style>
